package tlog

import "time"

var TlogRTField = "tlog_rt"

type Field struct {
	Key string
	Val any
}

func RTField(startTime time.Time, endTime time.Time) Field {
	return Field{
		Key: TlogRTField,
		Val: endTime.Sub(startTime).String(),
	}
}

var (
	TlogTraceId   = "tlog_id"
	TlogRelatedId = "tlog_relatedId"
	TlogPath      = "tlog_path"
	TlogMsg       = "tlog_msg"
	TlogLabel     = "tlog_label"
	TlogLevel     = "tlog_level"
)

type Content struct {
	TraceId   string `json:"tlog_traceId"`
	Path      string `json:"tlog_path"`
	RelatedId string `json:"tlog_relatedId"`
	Msg       string `json:"tlog_msg"`
	Label     string `json:"tlog_label"`
	Level     string `json:"tlog_level"`
}

func (c *Content) BuildFields(fields ...Field) map[string]interface{} {
	res := map[string]interface{}{
		TlogTraceId:   c.TraceId,
		TlogRelatedId: c.RelatedId,
		TlogPath:      c.Path,
		TlogMsg:       c.Msg,
		TlogLabel:     c.Label,
		TlogLevel:     c.Level,
	}

	for _, field := range fields {
		res[field.Key] = field.Val
	}

	return res
}
